<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">{- |
   Module      :  System.Win32.Console.HWND
   Copyright   :  2009 Balazs Komuves, 2013 shelarcy
   License     :  BSD-style

   Maintainer  :  shelarcy@gmail.com
   Stability   :  Provisional
   Portability :  Non-portable (Win32 API)

   Get the handle of the current console window.
-}</span><span>
</span><span id="line-12"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.Win32.Console.HWND</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="System.Win32.Console.HWND.html#getConsoleHWND"><span class="hs-identifier">getConsoleHWND</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-13"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Concurrent.html#"><span class="hs-identifier">Control.Concurrent</span></a></span><span>           </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.IO.html#threadDelay"><span class="hs-identifier">threadDelay</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-14"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Exception.html#"><span class="hs-identifier">Control.Exception</span></a></span><span>            </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Control.Exception.Base.html#bracket"><span class="hs-identifier">bracket</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.Ptr.html#"><span class="hs-identifier">Foreign.Ptr</span></a></span><span>                  </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#nullPtr"><span class="hs-identifier">nullPtr</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-16"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Graphics.Win32.Window.html"><span class="hs-identifier">Graphics.Win32.Window</span></a></span><span>        </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Graphics.Win32.Window.html#c_FindWindow"><span class="hs-identifier">c_FindWindow</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-17"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Graphics.Win32.GDI.Types.html"><span class="hs-identifier">Graphics.Win32.GDI.Types</span></a></span><span>     </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Graphics.Win32.GDI.Types.html#HWND"><span class="hs-identifier">HWND</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Win32.Console.Title.html"><span class="hs-identifier">System.Win32.Console.Title</span></a></span><span>   </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="System.Win32.Console.Title.html#getConsoleTitle"><span class="hs-identifier">getConsoleTitle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Win32.Console.Title.html#setConsoleTitle"><span class="hs-identifier">setConsoleTitle</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Win32.Process.html"><span class="hs-identifier">System.Win32.Process</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="System.Win32.Process.html#getCurrentProcessId"><span class="hs-identifier">getCurrentProcessId</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Win32.String.html"><span class="hs-identifier">System.Win32.String</span></a></span><span>          </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="System.Win32.Types.html#withTString"><span class="hs-identifier">withTString</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Win32.Time.html"><span class="hs-identifier">System.Win32.Time</span></a></span><span>            </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="System.Win32.Time.html#getTickCount"><span class="hs-identifier">getTickCount</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-22"></span><span>
</span><span id="line-23"></span><span class="hs-comment">-- | Get the handle of the current console window by using window's title.</span><span>
</span><span id="line-24"></span><span class="hs-comment">-- See: &lt;http://support.microsoft.com/kb/124103&gt;</span><span>
</span><span id="line-25"></span><span class="annot"><a href="System.Win32.Console.HWND.html#getConsoleHWND"><span class="hs-identifier hs-type">getConsoleHWND</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="Graphics.Win32.GDI.Types.html#HWND"><span class="hs-identifier hs-type">HWND</span></a></span><span>
</span><span id="line-26"></span><span id="getConsoleHWND"><span class="annot"><span class="annottext">getConsoleHWND :: IO HWND
</span><a href="System.Win32.Console.HWND.html#getConsoleHWND"><span class="hs-identifier hs-var hs-var">getConsoleHWND</span></a></span></span><span>
</span><span id="line-27"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO String -&gt; (String -&gt; IO ()) -&gt; (String -&gt; IO HWND) -&gt; IO HWND
forall a b c. IO a -&gt; (a -&gt; IO b) -&gt; (a -&gt; IO c) -&gt; IO c
</span><a href="../../base/src/Control.Exception.Base.html#bracket"><span class="hs-identifier hs-var">bracket</span></a></span><span> </span><span class="annot"><span class="annottext">IO String
</span><a href="System.Win32.Console.Title.html#getConsoleTitle"><span class="hs-identifier hs-var">getConsoleTitle</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="System.Win32.Console.Title.html#setConsoleTitle"><span class="hs-identifier hs-var">setConsoleTitle</span></a></span><span> </span><span class="annot"><span class="annottext">((String -&gt; IO HWND) -&gt; IO HWND) -&gt; (String -&gt; IO HWND) -&gt; IO HWND
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">String
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-28"></span><span>        </span><span id="local-6989586621679117344"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679117344"><span class="hs-identifier hs-var">time</span></a></span></span><span>   </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO DWORD
</span><a href="System.Win32.Time.html#getTickCount"><span class="hs-identifier hs-var">getTickCount</span></a></span><span>
</span><span id="line-29"></span><span>        </span><span id="local-6989586621679117343"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679117343"><span class="hs-identifier hs-var">pid</span></a></span></span><span>    </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO DWORD
</span><a href="System.Win32.Process.html#getCurrentProcessId"><span class="hs-identifier hs-var">getCurrentProcessId</span></a></span><span>
</span><span id="line-30"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679117339"><span class="annot"><span class="annottext">unique :: String
</span><a href="#local-6989586621679117339"><span class="hs-identifier hs-var hs-var">unique</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679117344"><span class="hs-identifier hs-var">time</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679117343"><span class="hs-identifier hs-var">pid</span></a></span><span>
</span><span id="line-31"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="System.Win32.Console.Title.html#setConsoleTitle"><span class="hs-identifier hs-var">setConsoleTitle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679117339"><span class="hs-identifier hs-var">unique</span></a></span><span>
</span><span id="line-32"></span><span>        </span><span class="annot"><span class="annottext">Int -&gt; IO ()
</span><a href="../../base/src/GHC.Conc.IO.html#threadDelay"><span class="hs-identifier hs-var">threadDelay</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">42</span></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1000</span></span><span class="hs-special">)</span><span>
</span><span id="line-33"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; (LPTSTR -&gt; IO HWND) -&gt; IO HWND
forall a. String -&gt; (LPTSTR -&gt; IO a) -&gt; IO a
</span><a href="System.Win32.Types.html#withTString"><span class="hs-identifier hs-var">withTString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679117339"><span class="hs-identifier hs-var">unique</span></a></span><span> </span><span class="annot"><span class="annottext">((LPTSTR -&gt; IO HWND) -&gt; IO HWND) -&gt; (LPTSTR -&gt; IO HWND) -&gt; IO HWND
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679117336"><span class="annot"><span class="annottext">LPTSTR
</span><a href="#local-6989586621679117336"><span class="hs-identifier hs-var">punique</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-34"></span><span>            </span><span class="annot"><span class="annottext">LPTSTR -&gt; LPTSTR -&gt; IO HWND
</span><a href="Graphics.Win32.Window.html#c_FindWindow"><span class="hs-identifier hs-var">c_FindWindow</span></a></span><span> </span><span class="annot"><span class="annottext">LPTSTR
forall a. Ptr a
</span><a href="../../base/src/GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span> </span><span class="annot"><span class="annottext">LPTSTR
</span><a href="#local-6989586621679117336"><span class="hs-identifier hs-var">punique</span></a></span><span>
</span><span id="line-35"></span></pre></body></html>